package org.tech4j.edi.persistence.api;

import org.tech4j.common.core.model.page.PageQuery;
import org.tech4j.common.core.model.page.PageResult;
import org.tech4j.common.core.model.request.PageRequest;
import org.tech4j.edi.common.entity.RetryBizRecord;
import org.tech4j.edi.common.enums.RetryStatusEnum;
import org.tech4j.edi.common.result.EdiResult;
import org.tech4j.edi.persistence.api.query.RetryCountQuery;
import org.tech4j.edi.persistence.api.query.RetryRecordQuery;
import org.tech4j.edi.persistence.api.query.RetryRecordScanQuery;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/7 11:33
 **/
public interface RetryRecordPersistService {

    /**
     * 持久化重试记录
     * @param retryBizRecord retryBizRecord
     * @return recordId
     */
    EdiResult<String> persistRetryRecord(RetryBizRecord retryBizRecord);

    /**
     * 根据id获取重试记录
     * @param id recordId
     * @param bizType bizType
     * @return
     */
    RetryBizRecord getRetryBizRecordById(String id, String bizType);

    /**
     * 更新重试状态
     * @param retryBizRecord retryBizRecord
     * @param status status
     * @return EdiResult
     */
    EdiResult<Void> updateRetryStatus(RetryBizRecord retryBizRecord, RetryStatusEnum status);

    /**
     * 更新重试状态
     * @param retryBizRecord retryBizRecord
     * @param status status
     * @param remark remark
     * @return EdiResult
     */
    EdiResult<Void> updateRetryStatusAndRemark(RetryBizRecord retryBizRecord, RetryStatusEnum status, String remark);

    /**
     * 获取重试记录最小id
     * @param env env
     * @param startTime startTime
     * @param endTime endTime
     * @return recordId
     */
    String getRetryMinId(String env, LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 获取重试记录最大id
     * @param env  env
     * @param startTime startTime
     * @param endTime endTime
     * @return recordId
     */
    String getRetryMaxId(String env, LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 统计重试记录数
     * @param query RetryCountQuery
     * @return Long
     */
    Long count(RetryRecordQuery query);

    /**
     * 查询重试记录列表
     * @param query RetryRecordQuery
     * @return RetryBizRecord
     */
    List<RetryBizRecord> list(RetryRecordQuery query);

    /**
     * 分页查询重试记录列表
     * @param page PageQuery
     * @param query RetryRecordQuery
     * @return RetryBizRecord
     */
    PageResult<RetryBizRecord> page(PageQuery page, RetryRecordQuery query);

    /**
     * 查询重试扫描记录
     * @param query
     * @return
     */
    List<RetryBizRecord> scanRetryBizRecord(RetryRecordScanQuery query);
}
